package com.ccys.doctor.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.ccys.common.vo.ResponseResultApp;
import com.ccys.db.dto.doctor.patientMeasurement.UpdatePatientMeasurementDto;
import com.ccys.db.entity.TblMember;
import com.ccys.db.mapper.TblMemberMapper;
import com.ccys.doctor.service.PatientMeasurementService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @program: WhiteCoat
 * @description: 患者测量相关接口
 * @author: ZhangJingCan
 * @create: 2024-02-08 14:00
 **/

@Service
public class PatientMeasurementServiceImpl implements PatientMeasurementService {

    @Resource
    private TblMemberMapper tblMemberMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResponseResultApp updatePatientMeasurement(UpdatePatientMeasurementDto dto) {
        if (ObjectUtil.isEmpty(dto.getMem_id())) {
            return ResponseResultApp.error("The mem_id field is required.");
        }
        //查询患者
        TblMember member = tblMemberMapper.findById(dto.getMem_id());
        if (ObjectUtil.isEmpty(member)) {
            return ResponseResultApp.error("Member invalid");
        }
        //对方接口做的是两个值都可以为null
        if (ObjectUtil.isNotEmpty(dto.getHeight())) {
            member.setHeight(dto.getHeight());
        }
        if (ObjectUtil.isEmpty(dto.getWeight())) {
            member.setWeight(dto.getWeight());
        }
        tblMemberMapper.updateByPrimaryKeySelective(member);
        return ResponseResultApp.success();
    }
}
